package com.web.dao;

import com.web.entity.CycleRegister;
import com.web.entity.Member;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

/**
 * @author FDjavaone
 */
public interface CycleRegisterMapper {
    @Delete({
        "delete from t_cycle_register",
        " where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
        "insert into t_cycle_register (m_id, phone, ",
        " password, status, ",
        " create_time, modify_time)",
        " values (#{mId,jdbcType=BIGINT}, #{phone,jdbcType=VARCHAR}, ",
        " #{password,jdbcType=VARCHAR}, #{status,jdbcType=INTEGER}, ",
        " #{createTime,jdbcType=TIMESTAMP}, #{modifyTime,jdbcType=TIMESTAMP})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Long.class)
    int insert(CycleRegister record);

    @InsertProvider(type=CycleRegisterSqlProvider.class, method="insertSelective")
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Long.class)
    int insertSelective(CycleRegister record);

    @Select({
        "select",
        " id, m_id, phone, password, status, create_time, modify_time",
        " from t_cycle_register",
        " where id = #{id,jdbcType=BIGINT}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="m_id", property="mId", jdbcType=JdbcType.BIGINT),
        @Result(column="phone", property="phone", jdbcType=JdbcType.VARCHAR),
        @Result(column="password", property="password", jdbcType=JdbcType.VARCHAR),
        @Result(column="status", property="status", jdbcType=JdbcType.INTEGER),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="modify_time", property="modifyTime", jdbcType=JdbcType.TIMESTAMP)
    })
    CycleRegister selectByPrimaryKey(Long id);

    @UpdateProvider(type=CycleRegisterSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(CycleRegister record);

    @Update({
        "update t_cycle_register",
        " set m_id = #{mId,jdbcType=BIGINT},",
          " phone = #{phone,jdbcType=VARCHAR},",
          " password = #{password,jdbcType=VARCHAR},",
          " status = #{status,jdbcType=INTEGER},",
          " create_time = #{createTime,jdbcType=TIMESTAMP},",
          " modify_time = #{modifyTime,jdbcType=TIMESTAMP}",
        " where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(CycleRegister record);


    @SelectProvider(type = CycleRegisterSqlProvider.class, method = "selectUnRegister")
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "phone", property = "phone", jdbcType = JdbcType.VARCHAR),
            @Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR),
            @Result(column = "password", property = "password", jdbcType = JdbcType.VARCHAR),
            @Result(column = "member_type", property = "memberType", jdbcType = JdbcType.VARCHAR),
            @Result(column = "identity_no", property = "identityNo", jdbcType = JdbcType.VARCHAR),
            @Result(column = "auth_status", property = "authStatus", jdbcType = JdbcType.INTEGER),
            @Result(column = "header_img", property = "headerImg", jdbcType = JdbcType.VARCHAR),
            @Result(column = "invite_code", property = "inviteCode", jdbcType = JdbcType.VARCHAR),
            @Result(column = "invited_code", property = "invitedCode", jdbcType = JdbcType.VARCHAR),
            @Result(column = "nick_name", property = "nickName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "gender", property = "gender", jdbcType = JdbcType.VARCHAR),
            @Result(column = "pay_password", property = "payPassword", jdbcType = JdbcType.VARCHAR),
            @Result(column = "consume_amt", property = "consumeAmt", jdbcType = JdbcType.DECIMAL),
            @Result(column = "bonus_amt", property = "bonusAmt", jdbcType = JdbcType.DECIMAL),
            @Result(column = "level", property = "level", jdbcType = JdbcType.INTEGER),
            @Result(column = "enabled", property = "enabled", jdbcType = JdbcType.INTEGER),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "modify_time", property = "modifyTime", jdbcType = JdbcType.TIMESTAMP)
    })
    List<Member> selectUnRegister();


    @SelectProvider(type = CycleRegisterSqlProvider.class, method = "selectNeedChangePassword")
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "phone", property = "phone", jdbcType = JdbcType.VARCHAR),
            @Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR),
            @Result(column = "password", property = "password", jdbcType = JdbcType.VARCHAR),
            @Result(column = "member_type", property = "memberType", jdbcType = JdbcType.VARCHAR),
            @Result(column = "identity_no", property = "identityNo", jdbcType = JdbcType.VARCHAR),
            @Result(column = "auth_status", property = "authStatus", jdbcType = JdbcType.INTEGER),
            @Result(column = "header_img", property = "headerImg", jdbcType = JdbcType.VARCHAR),
            @Result(column = "invite_code", property = "inviteCode", jdbcType = JdbcType.VARCHAR),
            @Result(column = "invited_code", property = "invitedCode", jdbcType = JdbcType.VARCHAR),
            @Result(column = "nick_name", property = "nickName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "gender", property = "gender", jdbcType = JdbcType.VARCHAR),
            @Result(column = "pay_password", property = "payPassword", jdbcType = JdbcType.VARCHAR),
            @Result(column = "consume_amt", property = "consumeAmt", jdbcType = JdbcType.DECIMAL),
            @Result(column = "bonus_amt", property = "bonusAmt", jdbcType = JdbcType.DECIMAL),
            @Result(column = "level", property = "level", jdbcType = JdbcType.INTEGER),
            @Result(column = "enabled", property = "enabled", jdbcType = JdbcType.INTEGER),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "modify_time", property = "modifyTime", jdbcType = JdbcType.TIMESTAMP)
    })
    List<Member> selectNeedChangePassword();

    @Select({
            "select",
            " id, m_id, phone, password, status, create_time, modify_time",
            " from t_cycle_register",
            " where m_id = #{id,jdbcType=BIGINT}"
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
            @Result(column="m_id", property="mId", jdbcType=JdbcType.BIGINT),
            @Result(column="phone", property="phone", jdbcType=JdbcType.VARCHAR),
            @Result(column="password", property="password", jdbcType=JdbcType.VARCHAR),
            @Result(column="status", property="status", jdbcType=JdbcType.INTEGER),
            @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="modify_time", property="modifyTime", jdbcType=JdbcType.TIMESTAMP)
    })
    CycleRegister selectByMid(Long id);
}